package com.ruibang.glass.produce.controller.yl;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.ruibang.glass.produce.domain.req.DefectSampleReq;
import com.ruibang.glass.produce.domain.resp.DefectSampleRateChart;
import com.ruibang.glass.produce.entity.DefectSample;
import com.ruibang.glass.produce.service.DefectSampleService;
import com.teaming.cloud.framework2.common.model.ResultBody;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;
import java.util.Map;


/**
 * <p>
 * 溶解缺陷取样 前端控制器
 * </p>
 *
 * @author songJinKang
 * @since 2024-04-28
 */
@RestController
@Validated
@RequestMapping("/api/produce/defect/sample")
@Api(value = "溶解缺陷取样控制器", tags = {"溶解缺陷取样接口"})
public class DefectSampleController {


    @Autowired
    private DefectSampleService defectSampleService;

    @GetMapping("/getDetail/{id}")
    @ApiOperation(value = "详情接口", notes = "详情接口")
    public ResultBody getDetail(@PathVariable(value = "id") String id) {
        return ResultBody.success(defectSampleService.getDetail(id));
    }

    @PostMapping("/insert")
    @ApiOperation(value = "新增溶解缺陷取样", notes = "新增溶解缺陷取样")
    public ResultBody insert(@RequestBody @Valid DefectSample defectSample) {
        defectSampleService.insert(defectSample);
        return ResultBody.success();
    }

    @GetMapping("/deleteById/{id}")
    @ApiOperation(value = "通过ID删除溶解缺陷取样", notes = "通过ID删除溶解缺陷取样")
    public ResultBody deleteById(@PathVariable(value = "id") String id) {
        defectSampleService.deleteById(id);
        return ResultBody.success();
    }

    @PostMapping("/update")
    @ApiOperation(value = "修改溶解缺陷取样", notes = "修改溶解缺陷取样")
    public ResultBody edit(@RequestBody @Valid DefectSample defectSample) {
        defectSampleService.edit(defectSample);
        return ResultBody.success();
    }

    @PostMapping("/pageQuery")
    @ApiOperation(value = "分页列表查询溶解缺陷取样", notes = "分页列表查询溶解缺陷取样")
    public ResultBody<IPage<DefectSample>> pageQuery(@RequestBody DefectSampleReq defectSampleReq) {
        return ResultBody.success(defectSampleService.pageQuery(defectSampleReq));
    }

    @PostMapping("/rateChart")
    @ApiOperation(value = "占比图", notes = "占比图")
    public ResultBody<DefectSampleRateChart> rateChart(@RequestBody DefectSampleReq defectSampleReq) {
        return ResultBody.success(defectSampleService.rateChart(defectSampleReq));
    }

    @PostMapping("/analysisChart")
    @ApiOperation(value = "分析图", notes = "分析图")
    public ResultBody<Map<String, Object>> analysisChart(@RequestBody @Valid DefectSampleReq defectSampleReq) {
        return ResultBody.success(defectSampleService.analysisChart(defectSampleReq));
    }
}
